/*
 * Copyright 2009 Andrey Khalzov, and individual contributors as indicated by the @author tag.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 */

package org.wannatrak.test.generator.random;

import org.wannatrak.GpsData;
import org.wannatrak.test.generator.GpsDataGenerator;

import java.util.Random;

/**
 * Created 16.12.2009 1:40:51
 *
 * @author Andrey Khalzov
 */
public class RandomGpsDataGenerator implements GpsDataGenerator {

    private final String sourceId;
    private final String sourceType;
    private final int statusCode;
    private final Random random = new Random();

    public RandomGpsDataGenerator(String sourceId, String sourceType) {
        this(sourceId, sourceType, 1);
    }

    public RandomGpsDataGenerator(String sourceId, String sourceType, int statusCode) {
        this.sourceId = sourceId;
        this.sourceType = sourceType;
        this.statusCode = statusCode;
    }

    @Override
    public GpsData next() {
        return new GpsDataImpl(
                sourceId,
                sourceType,
                System.currentTimeMillis(),
                random.nextDouble(),
                random.nextDouble(),
                random.nextDouble(),
                random.nextDouble(),
                random.nextDouble(),
                random.nextDouble(),
                statusCode
        );
    }

    private static class GpsDataImpl implements GpsData {
        final String sourceId;
        final String sourceType;
        final long timestamp;
        final double latitude;
        final double longitude;
        final double altitude;
        final double speedKph;
        final double heading;
        final double odometerKm;
        final int statusCode;

        private GpsDataImpl(
                String sourceId,
                String sourceType,
                long timestamp,
                double latitude,
                double longitude,
                double altitude,
                double speedKph,
                double heading,
                double odometerKm,
                int statusCode
        ) {
            this.sourceId = sourceId;
            this.sourceType = sourceType;
            this.timestamp = timestamp;
            this.latitude = latitude;
            this.longitude = longitude;
            this.altitude = altitude;
            this.speedKph = speedKph;
            this.heading = heading;
            this.odometerKm = odometerKm;
            this.statusCode = statusCode;
        }

        @Override
        public String getSourceId() {
            return sourceId;
        }

        @Override
        public String getSourceType() {
            return sourceType;
        }

        @Override
        public long getTimestamp() {
            return timestamp;
        }

        @Override
        public double getLatitude() {
            return latitude;
        }

        @Override
        public double getLongitude() {
            return longitude;
        }

        @Override
        public double getAltitude() {
            return altitude;
        }

        @Override
        public double getSpeedKph() {
            return speedKph;
        }

        @Override
        public double getHeading() {
            return heading;
        }

        @Override
        public double getOdometerKm() {
            return odometerKm;
        }

        @Override
        public int getStatusCode() {
            return statusCode;
        }
    }
}
